home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / cert / trk3_eg / ole2_xl / ole_ex.frm (.txt) next >
Encoding:
Visual Basic Form  |  1994-11-29  |  1.4 KB  |  49 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "VB to Excel"
  4.    ClientHeight    =   3585
  5.    ClientLeft      =   1635
  6.    ClientTop       =   1485
  7.    ClientWidth     =   6675
  8.    Height          =   3990
  9.    Left            =   1575
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3585
  12.    ScaleWidth      =   6675
  13.    Top             =   1140
  14.    Width           =   6795
  15.    Begin CommandButton Command1 
  16.       Caption         =   "OLE Automation to Excel"
  17.       Height          =   855
  18.       Left            =   1680
  19.       TabIndex        =   0
  20.       Top             =   1200
  21.       Width           =   2535
  22.    End
  23. Option Explicit
  24. Sub Command1_Click ()
  25. On Error GoTo errole
  26. Dim xl As object
  27. Set xl = GetObject(, "excel.application")
  28.     xl.workbooks.Add
  29.     xl.visible = True
  30.     xl.Range("A1").Select
  31.     xl.ActiveCell.FormulaR1C1 = "4"
  32.     xl.Range("A2").Select
  33.     xl.ActiveCell.FormulaR1C1 = "5"
  34.     xl.Range("A3").Select
  35.     xl.ActiveCell.FormulaR1C1 = "6"
  36.     xl.Range("A4").Select
  37.     xl.ActiveCell.FormulaR1C1 = "3"
  38.     xl.Range("A1:A4").Select
  39.     xl.ActiveSheet.ChartObjects.Add(81, 41.25, 267, 124.5).Select
  40.     xl.Application.CutCopyMode = False
  41.     xl.ActiveChart.ChartWizard xl.Range("A1:A4"), 3, 6, 2, 0, 0, 1
  42. Exit Sub
  43. errole:
  44. If Err = 429 Then
  45. Set xl = CreateObject("Excel.application.5")
  46. Resume Next
  47. End If
  48. End Sub
  49.